<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button class="btn1">post</button>
    <p>Fetch是js内置的发请求方式，不需要安装其他依赖</p>
    <script>
        // 第一个参数 url
        // 第二个参数 配置项，选填。请求方式、数据、请求头等
        fetch('http://localhost:3000/play/category')
            .then(res => {
                return res.json()
            })
            .then(res => {
                console.log(111, res);
            })

        let btn1 = document.querySelector('.btn1');
        btn1.onclick = function () {
            console.log('post请求');
            let data = {
                phone: '18937366671',
                code: 'r2b7',
                username: 'aaa111',
                password: 'abcd1234_'
            }
            fetch('http://localhost:3000/users/register', {
                method: 'post',
                body: JSON.stringify(data)
            })
                .then(res => {
                    res.json
                })
                .then(res => {
                    console.log('post的数据：', res);
                })
        }
    </script>
</body>

</html>